package com.coolwen.springmvc.dao;


import com.coolwen.springmvc.model.User;
import com.coolwen.springmvc.model.UserGroupDto;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author CoolWen
 * @version 2018-10-12 10:57
 */
@Repository("userDao")
public class UserDao extends BaseDao<User> implements IUserDao {
    @Override
    public User loadByName(String username) {
        String hql = "from User where username=?";

//        String hql = "select u from User as u where u.username=?";
        User u = new User();
        return u = (User) this.getSession().createQuery(hql).setParameter(0, username).uniqueResult();
    }

    @Override
    public List<UserGroupDto> listUserGroupDto() {
        String hql = "select new com.coolwen.springmvc.model.UserGroupDto" +
                "(u.id,u.username,u.password,u.nickname,u.gid,g.groupname) " +
                "from User u,Group g where u.gid=g.id";
        return this.getSession().createQuery(hql).list();
    }
}
